package edu.cdbi.database;

import junit.framework.TestCase;
import edu.cdbi.model.instance.Teacher;

public class TeacherManagementTest extends TestCase {
	
	private TeacherManagement management;

	protected void setUp() throws Exception {
		super.setUp();
		management = new TeacherManagement();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testInsert() {
		int id = management.insert("teacher", "teacher@edu.tw");
		
		int counter = 0;
		for(Teacher teacher :management.getList()){
			if(teacher.getId() == id){
				counter++;
			}
		}
		assertTrue(counter == 1);
		
		management.delete(id);
	}

	public void testGetList() {
		/*讀取2筆測試資料，測試搜尋功能是否正確
		 * 分別為
		 * 1. rose, rose@edu.tw
		 * 2. mary, mary@edu.tw
		 */
		int counter = 0;
		for(Teacher teacher : management.getList()){
			if(teacher.getName().equals("rose") &&
					teacher.getEmail().equals("rose@edu.tw")){
				counter ++;
			}else if(teacher.getName().equals("mary") &&
					teacher.getEmail().equals("mary@edu.tw")){
				counter ++;
			}
		}
		
		assertTrue(counter == 2);
	}
	
	public void testDelete() {
		/*刪除1筆測試資料，測試刪除功能是否正確
		 * 分別為
		 * 1. 1, wan, wan@us
		 */
		int counter = 0;
		for(Teacher teacher : management.getList()){
			if(teacher.getId() == 1){
				counter ++;
			}
		}
		assertTrue(counter == 1);
		
		management.delete(1);
		for(Teacher teacher : management.getList()){
			if(teacher.getId() == 1){
				counter --;
			}
		}
		assertTrue(counter == 1);
	}

}
